package com.zjc;

import java.lang.reflect.Field;

/**
 * Created by lv_03575 on 2017/9/27.
 */
public class CheckProcesser {

    public  static  void check(Object obj) throws IllegalAccessException {
        Class<? extends Object> cla=obj.getClass();
        Field []fields=cla.getDeclaredFields();
        for(Field f:fields){
            f.setAccessible(true);
            NotNull notNull=f.getAnnotation(NotNull.class);
            Object value=f.get(obj);
            if(notNull==null){
                return;
            }
            String desc=notNull.msg().equals("")?f.getName():notNull.msg();
            if(!notNull.nullable()){
                if(value==null||"".equals(value)){
                    throw new RuntimeException(desc+"_不能为空");
                }

            }
            f.setAccessible(false);
        }
    }
}
